import { getEcCom } from '../util/convert';
import base from '../util/base';
const { WeaTools } = getEcCom();

const appendUserParams = (params) =>{
	const { commonParam } = base.globalStore;
	const arr = ["wfTestStr", "f_weaver_belongto_userid", "f_weaver_belongto_usertype"];
	arr.map(key =>{
		if(!(key in params) && key in commonParam)
			params[key] = commonParam[key];
	});
}

const appendAuthParams = (params) =>{
	const { commonParam } = base.globalStore;
	const arr = ["authStr", "authSignatureStr"];
	arr.map(key =>{
		if(!(key in params) && key in commonParam)
			params[key] = commonParam[key];
	});
}

//表单加载基础信息
export const loadBaseInfo = params => {
	return WeaTools.callApi('/api/workflow/reqform/loadForm', 'POST', params);
}

//模板预览加载数据
export const loadPreViewInfo = params => {
	return WeaTools.callApi('/api/workflow/reqform/loadPreView', 'POST', params);
}

//耗时信息入库
export const writeDurationTimeInfo = params => {
	return WeaTools.callApi('/api/systemViewLog/home/InsertSystemPageViewLog', 'POST', params);
}

//明细数据
export const loadDetailData = params => {
	appendUserParams(params);
	return WeaTools.callApi('/api/workflow/reqform/detailData', 'POST', params);
}

//明细数据keyid
export const getDetailDataKeyIds = params => {
	appendUserParams(params);
	return WeaTools.callApi('/api/workflow/reqform/detailDataKeyId', 'POST', params);
}

//改变明细分页条数
export const saveDetailPaging = params => {
	appendUserParams(params);
	return WeaTools.callApi('/api/workflow/reqform/saveDetailPaging', 'POST', params);
}

//签字意见列表
export const loadRequestLog = params => {
	appendUserParams(params);
	return WeaTools.callApi('/api/workflow/reqform/requestLog', 'POST', params);
}

//加载签字意见基本信息
export  const getRequestLogBaseInfo = params => {
	appendUserParams(params);
    return WeaTools.callApi('/api/workflow/reqform/getRequestLogBaseInfo', 'POST', params);
}

//加载签字意见列表数据
export  const getRequestLogList = params => {
	appendUserParams(params);
    return WeaTools.callApi('/api/workflow/reqform/getRequestLogList', 'POST', params);
}

//更新意见列表分页
export const updateRequestLogPageSize = params => {
	appendUserParams(params);
	return WeaTools.callApi('/api/workflow/reqform/updateRequestLogPageSize', 'POST', params);
}

//意见输入框
export const getSignInput = params => {
	appendUserParams(params);
	appendAuthParams(params);
	return WeaTools.callApi('/api/workflow/reqform/signInput', 'POST', params);
}

//节点意见设置
export const getNodeSignSet = params => {
	appendUserParams(params);
	appendAuthParams(params);
	return WeaTools.callApi('/api/workflow/reqform/getNodeSignSet', 'GET', params);
}

//右键按钮
export const getRightMenu = params => {
	appendUserParams(params);
	return WeaTools.callApi('/api/workflow/reqform/rightMenu', 'POST', params);
}

//请求状态更新(已读等)
export const updateReqInfo = params => {
	appendUserParams(params);
	return WeaTools.callApi('/api/workflow/reqform/updateReqInfo', 'POST', params);
}

//加载代码块
export const loadScriptContent = params => {
	appendUserParams(params);
	return WeaTools.callApi('/api/workflow/reqform/scripts', 'GET', params,'text');
}

//加载custompage
export const loadCustompage = (address, params) => {
	appendUserParams(params);
	params["__address__"] = address;
	return WeaTools.callApi('/workflow/request/CustomPageForward.jsp', 'POST', params, 'text');
}

//加载自定义开发文件列表
export const loadInjectDevFile = (params) => {
	appendUserParams(params);
	return WeaTools.callApi('/api/workflow/injectDev/loadFormDevFileList', 'POST', params);
}

//text方式加载指定路径内容
export const loadHrefTextContent = (address, params) => {
	appendUserParams(params);
	return WeaTools.callApi(address, 'GET', params, 'text');
}

//判断退回方式
export const judgeRejectWay = params => {
	appendUserParams(params);
	return WeaTools.callApi('/api/workflow/reqform/judgeRejectWay', 'POST', params);
}

//加载流程状态
export const getWfStatus = params => {
	appendUserParams(params);
	appendAuthParams(params);
	return WeaTools.callApi('/api/workflow/reqform/wfstatusnew', 'POST', params);
}

//加载流程状态计数
export const getWfStatusCount = params => {
	appendUserParams(params);
	appendAuthParams(params);
	return WeaTools.callApi('/api/workflow/reqform/wfstatuscount', 'POST', params);
}

export const updateUserTxStatus = params => {
	appendUserParams(params);
	return WeaTools.callApi('/api/workflow/reqform/updateUserTxStatus', 'POST', params);
}

//字段联动接口
export const reqDataInputResult = params => {
	appendUserParams(params);
	return WeaTools.callApi('/api/workflow/linkage/reqDataInputResult', 'POST', params);
}

//SQL联动接口
export const reqFieldSqlResult = params => {
	appendUserParams(params);
	return WeaTools.callApi('/api/workflow/linkage/reqFieldSqlResult', 'POST', params);
}

//日期时间计算接口
export const reqDateTimeResult = params => {
	appendUserParams(params);
	return WeaTools.callApi('/api/workflow/linkage/reqDateTimeResult', 'POST', params);
}

//生成流程编号
export const createWfCode = params => {
	appendUserParams(params);
	return WeaTools.callApi('/api/workflow/reqform/createWfCode','POST',params);
}

export const loadWfCodeFieldValueInfo = params => {
	appendUserParams(params);
	return WeaTools.callApi('/api/workflow/reqform/loadWfCodeFieldValueInfo','POST',params);
}

export const functionLink = params => {
	appendUserParams(params);
	return WeaTools.callApi('/api/workflow/reqform/functionLink','POST',params);
}

export const reqOperate = (actionType,params) => {
	appendUserParams(params);
	return WeaTools.callApi('/api/workflow/reqform/'+actionType,'POST',params);
}
export const triggerSubWf = (params) => {
	appendUserParams(params);
	return WeaTools.callApi('/api/workflow/reqform/triggerSubWf','POST',params);
}
export const getUploadFileInfo = (params) => {
	appendUserParams(params);
	return WeaTools.callApi('/api/workflow/reqform/getUploadFileInfo','POST',params);
}
export const requestImport = (params) => {
	appendUserParams(params);
	return WeaTools.callApi('/api/workflow/reqform/requestImport','POST',params);
}

export const getReqInterventionInfo = (params) => {
	appendUserParams(params);
	return WeaTools.callApi('/api/workflow/monitor/intervention','POST',params);
}

export const getInterventionUser = (params) => {
	appendUserParams(params);
	return WeaTools.callApi('/api/workflow/monitor/getUsers','POST',params);
}

//异常处理选择操作者
export const chooseExceptionOperator = (params) => {
	appendUserParams(params);
	return WeaTools.callApi('/api/workflow/reqform/chooseExceptionOperator','POST',params);
}

//超时设置
export const overTimeSetting = (params) => {
	appendUserParams(params);
	return WeaTools.callApi('/api/workflow/reqform/overTimeSetting','POST',params);
}

//流程撤回
export const requestWithDraw = (params) => {
	appendUserParams(params);
	return WeaTools.callApi('/api/workflow/reqform/requestWithdraw','POST',params);
}

//打印日志基础信息
export const getPrintLogBase = (params) => {
	appendUserParams(params);
	return WeaTools.callApi('/api/workflow/reqform/getPrintLogBase','POST',params);
}

//打印日志数据信息
export const getPrintLogData = (params) => {
	appendUserParams(params);
	return WeaTools.callApi('/api/workflow/reqform/getPrintLogData','POST',params);
}

//自由流转读取数据
export const freeFlowRead = (params) => {
	appendUserParams(params);
	return WeaTools.callApi('/api/workflow/reqform/freeFlowRead','POST',params);
}

//自由流转保存数据
export const freeFlowSave = (params) => {
	appendUserParams(params);
	return WeaTools.callApi('/api/workflow/reqform/freeFlowSave','POST',params);
}

//流程编辑锁定相关操作
export const editLockOper = (params) => {
	appendUserParams(params);
	return WeaTools.callApi('/api/workflow/reqform/editLockOper','POST',params);
}

//表单打印获取打印模板信息
export const loadPrintTemplates = (params) => {
	// appendUserParams(params);
	return WeaTools.callApi('/api/workflow/reqform/loadPrintTemplates','POST',params);
}

//表单打印获取打印模板信息
export const generatePrintLog = (params) => {
	// appendUserParams(params);
	return WeaTools.callApi('/api/workflow/reqform/generatePrintLog','POST',params);
}

//流程督办
export const doSupervise = params => {
    return WeaTools.callApi('/api/workflow/supervise/doSupervise', 'POST', params);
}

//获取扩展TAB
export const getFormTab = params => {
    return WeaTools.callApi('/api/workflow/reqform/getFormTab', 'POST', params);
}

//获取指定下一节点操作者condition
export const getSelectNextFlowCondition = params => {
    return WeaTools.callApi('/api/workflow/reqform/getSelectNextFlowCondition', 'POST', params);
}

//获取指定下一节点流转节点信息
export const getSelectFlowNodeInfo = params => {
    return WeaTools.callApi('/api/workflow/reqform/getSelectFlowNodeInfo', 'POST', params);
}

//新版公式
export const getFormulasNew = params => {
	return WeaTools.callApi('/api/workflow/formula/getFormulas', 'POST', params);
}

//获取表单解析后生成的excel文件
export const getExportedExcel = params => {
	params = encodeURI(encodeURI(params));
    let formElement = $("<form>").attr("action", "/api/workflow/formexport/formExport").attr("method", "POST").attr("style", "display:none");
    let inputElement1 = $("<input>").attr("value", params).attr("name", "json").attr("type", "hidden");
    let inputElement2 = $("<input>").attr("value", $("#requestid").val()).attr("name", "requestid").attr("type", "hidden");
    formElement.append(inputElement1).append(inputElement2);
    $(document.body).append(formElement);
    formElement.submit();
    $(formElement).remove();
}

//获取表单解析后生成的pdf文件
export const getExportedPDF = (params, requestid) => {
    params = encodeURI(encodeURI(params).replace(/\+/g, "%2B"));
    let formElement = $("<form>").attr("action", "/api/workflow/formexport/formExportPDF").attr("method", "POST").attr("style", "display:none");
    let inputElement1 = $("<input>").attr("value", params).attr("name", "json").attr("type", "hidden");
    let inputElement2 = $("<input>").attr("value", requestid).attr("name", "requestid").attr("type", "hidden");
    formElement.append(inputElement1).append(inputElement2);
    $(document.body).append(formElement);
    formElement.submit();
    $(formElement).remove();
}

//意见征询收回
export const doTakeBack = params => {
    return WeaTools.callApi('/api/workflow/reqform/doTakeBack', 'POST', params);
}

//获取自定义操作菜单
export const getCustomOperation = params => {
	appendUserParams(params);
	return WeaTools.callApi('/api/workflow/reqform/getCustomOperation', 'POST', params);
}

//获取自定义操作菜单
export const runCustomOperationAction = params => {
	appendUserParams(params);
	return WeaTools.callApi('/api/workflow/reqform/runCustomOperationAction', 'GET', params);
}

//邮件催办信息
export const getSendEmailInfo = params => {
    return WeaTools.callApi('/api/workflow/supervise/getSendEmailInfo', 'POST', params);
}

//分享按钮是否显示
export const isShowShareBtn = () => {
	return WeaTools.callApi('/api/systeminfo/appsetting/get', 'GET', {});
}

//请求当前流程拥有的关注标签
export const getFormAttentionTag = (params={})=>{
	 params.src="getFormAttentionTag"
	return WeaTools.callApi('/api/workflow/requestAttention/getAttentionTypeSet', 'POST', params);
}

//结束意见征询
export const doTakEnd = (params={})=>{
	return WeaTools.callApi('/api/workflow/reqform/doTakEnd', 'POST', params);
}

export const checkJoin = () => {
	return WeaTools.callApi('/api/ec/dev/app/checkJoin', 'GET',{})
}

export const fieldLinkageCfg = (params={}) => {//
	return WeaTools.callApi('/api/workflow/reqform/riggerFieldLinkageCfg', 'POST',params);
}

export const formulaCfg = (params={}) => {//
    return WeaTools.callApi('/api/workflow/reqform/riggerFormulaCfg', 'POST',params);
}

//加签简易模式
export const loadCondition = (params={}) => {
	return WeaTools.callApi('/api/workflow/reqform/getTransferCondition', 'POST',params);
}

//获取智能预测流程图数据
export const getSimpleWfData = params => {
  return WeaTools.callApi('/api/workflow/layout/getSimpleModeData', 'POST', params);
}

//获取操作者信息
export const getOperator = params => {
  return WeaTools.callApi('/api/workflow/layout/getOperator', "POST", params);
}

//获取出口条件
export const getRuleCondition = params => {
  return WeaTools.callApi('/api/workflow/layout/getRuleCondition', 'POST', params);
}

//获取预测者信息
export const getForecastInfo = params => {
  return WeaTools.callApi('/api/workflow/layout/getForecastInfo', 'POST', params);
}

/**
 * 获取触发子流程的列表
 * @param params
 */
export const getTriggerSubWFList = params => {
	return WeaTools.callApi('/api/workflow/pocseconddev/getTriggerSubWFList', 'POST', params);
}

//获取套红预览地址
export const getThPreviewUrl = params=>{
	return WeaTools.callApi('/api/workflow/reqform/getThPreviewUrl', 'POST', params);
}

//获取套红预览地址
export const getThImageFileId = params=>{
	return WeaTools.callApi('/api/odoc/odocFile/selectMouldForTemplate', 'POST', params);
}

//获取套红模板列表
export const getThMouldList = params=>{
	return WeaTools.callApi('/api/workflow/reqform/getThMouldList', 'POST', params);
}

//获取连续处理信息
export const getContinnuationProcessInfo = params =>{
	return WeaTools.callApi('/api/workflow/reqlist/continnuationProcessInfo', 'POST', params);
}

//获取发票云的基本信息
export const getInvoiceCloudToken = params => {
	return WeaTools.callApi('/api/fna/fnaEmbileMicroReport/getInvoiceCloudToken','GET', params);
}
//发票id转发票云id
export const getFidOrEcid = params => {
	return WeaTools.callApi('/api/fna/invoiceLedger/getFidOrEcid','GET', params);
}

/** 获取流程图自由节点数据*/
export const getFreeNodeInfo = (params) => {
  return WeaTools.callApi('/api/workflow/freeFlow/getFreeNodeInfo', 'GET', params);
}
/** 获取流程图自由节点数据*/
export const saveFreeNodeInfo = (params) => {
  return WeaTools.callApi('/api/workflow/freeFlow/saveFreeNodeInfo', 'POST', params);
}
/** 获取流程图自由节点数据*/
export const getXml = (params) => {
  return WeaTools.callApi('/api/workflow/layout/getXml', 'POST', params);
}
/** 获取流程图自由节点模板*/
export const getFlowTemplateList = (params) => {
  return WeaTools.callApi('/api/workflow/freeFlow/getFlowTemplateList', 'GET', params);
}
/**获取添加模板基础数据*/
export const getAddTemplateBaseData = (params) => {
  return WeaTools.callApi('/api/workflow/freeFlow/getAddTemplateBaseData', 'GET', params);
}
/**自由流程流程图从模板导入*/
export const importFromTemplate = (params) => {
  return WeaTools.callApi('/api/workflow/freeFlow/importFromTemplate', 'POST', params);
}

/**自由流程流程图从模板导入*/
export const deleteTemplate = (params) => {
  return WeaTools.callApi('/api/workflow/freeFlow/deleteTemplate', 'POST', params);
}

export const getAccSecretLevelForDocid = (params) => {
	return WeaTools.callApi('/api/workflow/reqform/getAccSecretLevelForDocid', 'POST', params);
}